package com.github.abel533.aware;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.weaving.LoadTimeWeaverAware;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.jca.context.BootstrapContextAware;
import org.springframework.jmx.export.notification.NotificationPublisher;
import org.springframework.jmx.export.notification.NotificationPublisherAware;
import org.springframework.stereotype.Component;
import org.springframework.util.StringValueResolver;
import org.springframework.web.context.ServletConfigAware;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

import static com.github.abel533.C.print;

@Component
public class AwareImpl implements ServletConfigAware, ServletContextAware,
    BeanClassLoaderAware, BeanNameAware, BeanFactoryAware,
    LoadTimeWeaverAware, ResourceLoaderAware, EnvironmentAware,
    MessageSourceAware, EmbeddedValueResolverAware, ApplicationContextAware,
    ApplicationEventPublisherAware, NotificationPublisherAware, BootstrapContextAware {

    /**
     * 测试 LoadTimeWeaverAware
     *
     * @return
     * @throws Throwable
     */
    @Bean
    public InstrumentationLoadTimeWeaver loadTimeWeaver() throws Throwable {
        InstrumentationLoadTimeWeaver loadTimeWeaver = new InstrumentationLoadTimeWeaver();
        return loadTimeWeaver;
    }

    @Override
    public void setServletConfig(ServletConfig servletConfig) {
        print("ServletConfigAware#setServletConfig");
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        print("ServletContextAware#setServletContext");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        print("BeanClassLoaderAware#setBeanClassLoader");
    }

    @Override
    public void setBeanName(String s) {
        print("BeanNameAware#setBeanName");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        print("BeanFactoryAware#setBeanFactory");
    }

    @Override
    public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
        print("LoadTimeWeaverAware#loadTimeWeaverAware");
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        print("ResourceLoaderAware#setResourceLoader");
    }

    @Override
    public void setEnvironment(Environment environment) {
        print("EnvironmentAware#setEnvironment");
    }

    @Override
    public void setMessageSource(MessageSource messageSource) {
        print("MessageSourceAware#setMessageSource");
    }

    @Override
    public void setEmbeddedValueResolver(StringValueResolver stringValueResolver) {
        print("EmbeddedValueResolverAware#setEmbeddedValueResolver");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        print("ApplicationContextAware#setApplicationContext");
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        print("ApplicationEventPublisherAware#setApplicationEventPublisher");
    }

    @Override
    public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
        print("NotificationPublisherAware#setNotificationPublisher");
    }

    @Override
    public void setBootstrapContext(javax.resource.spi.BootstrapContext bootstrapContext) {
        print("BootstrapContextAware#setBootstrapContext");
    }

}
